import { Destroyable, react, reactJson, Event, track, bind } from "xbsj-xe2/dist-node/xe2-base-utils";
import { ESPoi2D } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';
export class PointCollection extends Destroyable {
    _map = new Map();

    // 全局显隐控制(EarthSDK响应式属性)
    _show = this.disposeVar(react(false));
    get show() { return this._show.value; }
    set show(value) { this._show.value = value }
    get showChanged() { return this._show.changed; }

    setData(data) {
        if (Array.isArray(data) && data.length > 0) {
            data.forEach(item => {
                if (!this._map.has(item.name)) this.create(item)
            })
        }
    }
    constructor(_myProjectManager) {
        super();
        this._myProjectManager = _myProjectManager
        this._sceneTree = _myProjectManager.createSceneTree("pointSceneTree", 28)

        // 全局控制显隐属性，监听变化
        this.showChanged.don((val) => {
            this._map.forEach(item => {
                item.sceneObject.show = val
            })
        })
    }

    create(item) {
        const { name, lon, lat } = item
        const treeItem = this._sceneTree.createSceneObjectTreeItem(ESPoi2D)
        treeItem.sceneObject.position = [lon, lat, 0]
        treeItem.sceneObject.name = name
        treeItem.sceneObject.mode = "P3D04"
        treeItem.sceneObject.show = this.show
        this._map.set(name, treeItem)
    }
}